public class GeneralHash {

    /**
     * 负载均衡（根据IP 路由到 指定服务器）
     *      1、普通hash算法
     */
    public static void main(String[] args) {
        String[] clients = new String[]{"123.0.1.44", "45.33.5.234", "243.44.65.64", "12.33.44.55", "99.88.27" +
                ".111"};

        int tomcatCount = 3;

        for(String client : clients){
            int clientHash = Math.abs(client.hashCode());
            int index = clientHash % tomcatCount;
            System.out.println(client + " 路由到了第" + index + "个服务器。");
        }
    }
}
